package cn.edu.buu.news.controller;

import cn.edu.buu.news.exception.NewsException;
import cn.edu.buu.news.vo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ControllerAdvice//aop:pointcut + advice + advisor
public class GlobalExceptionAdviceController {
    @ExceptionHandler(NewsException.class)
    public Result NewsException(NewsException newsException) {
        return Result.fail(newsException.getCode(), newsException.getMessage());
    }
    @ExceptionHandler(Throwable.class)
    public Result exceptionHandler(Throwable throwable){
        return Result.fail(500,throwable.getMessage());
    }

}
